package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;
import java.util.Map;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.AuctionAuctionListParser;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.task.CallbackSky;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;
import artid.com.arttogo.view.DynamicHeightImageView;

//机构详情里所有拍卖会的adapter
public class AucOrgDetAucListAdapter extends BaseAdapter {
    private Context mContext;
    LayoutInflater mInflater;
    ViewHolder holder;
    CallbackSky cs;
    public List<AuctionAuctionListParser> list;
    String width;

    public AucOrgDetAucListAdapter(Context mContext, List<AuctionAuctionListParser> list) {
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);

        Map<String, String> map = NetUtils
                .getDisplayMetrics((Activity) mContext);
        width = String.valueOf(Integer.valueOf(map.get(NetUtils.DM_WIDTH)) / 2);
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public void setData(List<AuctionAuctionListParser> listin) {
        list = listin;
        notifyDataSetChanged();
    }

    public void addData(List<AuctionAuctionListParser> listin) {
        list.addAll(listin);
        notifyDataSetChanged();
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        View v = convertView;
        if (v == null) {
            holder = new ViewHolder();
            v = LayoutInflater.from(mContext).inflate(R.layout.item_auc_org_detlist_auc, null);
            holder.img=(DynamicHeightImageView) v.findViewById(R.id.itemAucOrgDetAucList_img);
            holder.title=(TextView) v.findViewById(R.id.itemAucOrgDetAucList_title);
            holder.time=(TextView) v.findViewById(R.id.itemAucOrgDetAucList_time);
            holder.num=(TextView) v.findViewById(R.id.itemAucOrgDetAucList_num);
            holder.company=(TextView) v.findViewById(R.id.itemAucOrgDetAucList_company);
            holder.address=(TextView) v.findViewById(R.id.itemAucOrgDetAucList_address);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        holder.img.isRightAngle=true;
        holder.img.setHeight(list.get(position).getHeight());
        if (!TextUtils.isEmpty(list.get(position).getImgurl())) {
            Glide.with(mContext).load(list.get(position).getImgurl() + AppUtil.picWidthUrl)
                    .placeholder(R.drawable.ic_menu_rotate)
                    .error(R.drawable.ic_menu_rotate).into(holder.img);
        }
        holder.title.setText(list.get(position).getTitle());
        holder.time.setText(list.get(position).getStart_time()+"-"+list.get(position).getEnd_time());
        holder.num.setText(list.get(position).getSpecial_num()+"个专场 / "+list.get(position).getLotrecord_num()+"件备案 / "+list.get(position).getLot_num()+"拍品");
        holder.company.setText(list.get(position).getSeller_name());
        holder.address.setText(list.get(position).getAddress());
        return v;
    }
    class ViewHolder {
        DynamicHeightImageView img;
        TextView title,time,num,company,address;
    }
}
